﻿namespace Shortcuts.Views
{
    using Microsoft.Phone.Controls;
    using Microsoft.Phone.Shell;
    using Microsoft.Phone.Tasks;
    using Shortcuts.Globalization;
    using Shortcuts.ViewModels;
    using System;
    using System.Windows;

    public partial class AboutPage : PhoneApplicationPage
    {
        #region buttons

        ApplicationBarIconButton[] buttons = new ApplicationBarIconButton[3];

        void InitializeApplicationBarButtons()
        {
            buttons[0] = new ApplicationBarIconButton();
            buttons[0].Text = "back".Localized();
            buttons[0].IconUri = new Uri("/Assets/Images/back.png", UriKind.Relative);
            buttons[0].Click += OnBackIconButtonClick;

            buttons[1] = new ApplicationBarIconButton();
            buttons[1].Text = "like".Localized();
            buttons[1].IconUri = new Uri("/Assets/Images/like.png", UriKind.Relative);
            buttons[1].Click += OnLikeIconButtonClick;

            buttons[2] = new ApplicationBarIconButton();
            buttons[2].Text = "share".Localized();
            buttons[2].IconUri = new Uri("/Assets/Images/share.png", UriKind.Relative);
            buttons[2].Click += OnShareIconButtonClick;

            foreach (var button in buttons)
            {
                ApplicationBar.Buttons.Add(button);
            }
        }

        #endregion

        public AboutPage()
        {
            InitializeComponent();
            InitializeApplicationBarButtons();

            Loaded += OnPageLoaded;
        }

        void OnPageLoaded(object sender, RoutedEventArgs e)
        {
            DataContext = new AboutPageContext();
        }

        private void OnLikeIconButtonClick(object sender, EventArgs e)
        {
            MarketplaceReviewTask review = new MarketplaceReviewTask();
            review.Show();
        }

        private void OnShareIconButtonClick(object sender, EventArgs e)
        {
            MarketplaceDetailTask detail = new MarketplaceDetailTask();
            detail.Show();
        }

        private void OnBackIconButtonClick(object sender, EventArgs e)
        {
            NavigationService.GoBack();
        }
    }
}